package com.heima.kafkas.listener;

import com.alibaba.fastjson.JSON;
import com.heima.kafkas.pojo.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

import java.util.Optional;

@Component
@Slf4j
public class HellowListener {

    @KafkaListener(topics = "kafka-topic")
    public void onMessage(String message){
//        if(!StringUtils.isEmpty(message)){log.info("收到消息：" + message);}else {
//            log.info("收到消息为空");
//        }
        if (message != null) {
            log.info("收到message-{}", message);
        } else {
            log.info("收到消息为空");
        }

    }

    @KafkaListener(topics = "user-topic")
    public void onMessage2(String msg){
        if (msg != null) {
            User user1 = JSON.parseObject(msg, User.class);
            log.info("收到user-{}", user1);
        } else {
            log.info("收到消息为空");
        }
    }
}
